package com.egoo.ticket.server.service.impl;

import com.egoo.ticket.server.dao.EwsRoleDao;
import com.egoo.ticket.server.dao.EwsUserRoleDao;
import com.egoo.ticket.server.pojo.entity.EwsUserRole;
import com.egoo.ticket.server.service.UserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 */
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class UserRoleServiceImpl implements UserRoleService {
	@Autowired
	EwsUserRoleDao ewsUserRoleDao;
	@Autowired
	EwsRoleDao ewsRoleDao;

	@Override
	public List<String> selectByUserId(String userId, String tenantId) {
		List<EwsUserRole> userRoleList = ewsUserRoleDao.selectByUserId(userId,tenantId);
		List<String> roleIdList = new ArrayList<>();
		for (EwsUserRole ewsUserRole : userRoleList) {
			roleIdList.add(ewsUserRole.getRoleId());
		}
		return roleIdList;
	}

	@Override
	public EwsUserRole selectByUserIdAndRoleId(EwsUserRole ewsUserRole) {
		return ewsUserRoleDao.selectByUserIdAndRoleId(ewsUserRole);
	}

	@Override
	public Long addBatch(List<EwsUserRole> ewsUserRoleList) {
		log.info("新增用户角色同步数据为：" + ewsUserRoleList);
		return ewsUserRoleDao.insertBatch(ewsUserRoleList);
	}
}
